home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / caldat.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  91 lines

  1. ; $Id: caldat.pro,v 1.4 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1992-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. pro CALDAT, Julian, Month, Day, Year, Hour, Minute, Second
  8. ;+
  9. ; NAME:
  10. ;    CALDAT
  11. ;
  12. ; PURPOSE:
  13. ;    Return the calendar date and time given julian date.
  14. ;    This is the inverse of the function JULDAY.
  15. ; CATEGORY:
  16. ;    Misc.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    CALDAT, Julian, Month, Day, Year, Hour, Minute, Second
  20. ;    See also: julday, the inverse of this function.
  21. ;
  22. ; INPUTS:
  23. ;    JULIAN contains the Julian Day Number (which begins at noon) of the 
  24. ;    specified calendar date.  It should be a long integer.
  25. ; OUTPUTS:
  26. ;    (Trailing parameters may be omitted if not required.)
  27. ;    MONTH:    Number of the desired month (1 = January, ..., 12 = December).
  28. ;
  29. ;    DAY:    Number of day of the month.
  30. ;
  31. ;    YEAR:    Number of the desired year.
  32. ;
  33. ;    HOUR:    Hour of the day
  34. ;    Minute: Minute of the day
  35. ;    Second: Second (and fractions) of the day.
  36. ;
  37. ; COMMON BLOCKS:
  38. ;    None.
  39. ;
  40. ; SIDE EFFECTS:
  41. ;    None.
  42. ;
  43. ; RESTRICTIONS:
  44. ;    Accuracy using IEEE double precision numbers is approximately
  45. ;    1/10000th of a second.
  46. ;
  47. ; MODIFICATION HISTORY:
  48. ;    Translated from "Numerical Recipies in C", by William H. Press,
  49. ;    Brian P. Flannery, Saul A. Teukolsky, and William T. Vetterling.
  50. ;    Cambridge University Press, 1988 (second printing).
  51. ;
  52. ;    DMS, July, 1992.
  53. ;    Added Hours, Minutes, Secs, April, 1996.
  54. ;-
  55. ;
  56. ON_ERROR, 2        ; Return to caller if errors
  57.  
  58. IGREG = 2299161L    ;Beginning of Gregorian calendar
  59.  
  60. jul = long(julian)    ;Better be long
  61. f = julian - jul
  62. if f ne 0.0 then begin    ;Get hours, minutes, seconds.
  63.    hour = floor(f * 24.)
  64.    f = f - hour / 24.d0
  65.    minute = floor(f*1440)
  66.    second = (f - minute/1440.d0) * 86400.0d0
  67. endif else begin
  68.    hour = 0L
  69.    minute = 0L
  70.    second = 0L
  71. endelse
  72.    
  73.    
  74. if jul ge igreg then begin
  75.     jalpha = long(((jul - 1867216) - 0.25d0) / 36524.25)
  76.     ja = jul + 1 + jalpha - long(0.25d0 * jalpha)
  77. endif else ja = jul
  78.  
  79. jb = ja + 1524
  80. jc = long(6680.0 + ((jb-2439870)-122.1)/365.25)
  81. jd = long(365 * jc + (0.25 * jc))
  82. je = long((jb - jd) / 30.6001)
  83.  
  84. day = jb - jd - long(30.6001 * je)
  85. month = je -1
  86. if (month gt 12) then month = month - 12
  87. year = jc - 4715
  88. if month gt 2 then year = year - 1
  89. if year le 0 then year = year - 1
  90. end
  91.